package com.ruoyi.web.controller.base;

import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseEmerTeList;
import com.ruoyi.base.service.IBaseEmerTeListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应急TE单清单Controller
 * 
 * @author ruoyi
 * @date 2024-07-23
 */
@Api(description="检查单模板")
@RestController
@RequestMapping("/base/emerTeList")
public class BaseEmerTeListController extends BaseController
{
    @Autowired
    private IBaseEmerTeListService baseEmerTeListService;

    /**
     * 查询应急TE单清单列表
     */
    @ApiOperation("查询检查单模板列表")
    @GetMapping("/list")
    public TableDataInfo list(BaseEmerTeList baseEmerTeList)
    {
        startPage();
        baseEmerTeList.setUnitCode(getLoginUser().getUser().getUnit());
        List<BaseEmerTeList> list = baseEmerTeListService.selectBaseEmerTeListList(baseEmerTeList);
        return getDataTable(list);
    }

    /**
     * 导出应急TE单清单列表
     */
    @ApiOperation("导出检查单模板")
    @Log(title = "应急TE单清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseEmerTeList baseEmerTeList)
    {
        baseEmerTeList.setUnitCode(getLoginUser().getUser().getUnit());
        List<BaseEmerTeList> list = baseEmerTeListService.selectBaseEmerTeListList(baseEmerTeList);
        ExcelUtil<BaseEmerTeList> util = new ExcelUtil<BaseEmerTeList>(BaseEmerTeList.class);
        util.exportExcel(response, list, "应急TE单清单数据");
    }

    /**
     * 获取应急TE单清单详细信息
     */
    @ApiOperation("获取检查单模板")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(baseEmerTeListService.selectBaseEmerTeListByID(ID));
    }

    /**
     * 新增应急TE单清单
     */
    @ApiOperation("新增检查单模板")
    @Log(title = "应急TE单清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseEmerTeList baseEmerTeList)
    {
        baseEmerTeList.setID(UUID.randomUUID().toString().replace("-", ""));
        baseEmerTeList.setCreatedBy(getUserId().toString());
        baseEmerTeList.setCreatedTime(new Date());
        baseEmerTeList.setUnitCode(getLoginUser().getUser().getUnit());
        return toAjax(baseEmerTeListService.insertBaseEmerTeList(baseEmerTeList));
    }

    /**
     * 修改应急TE单清单
     */
    @ApiOperation("修改检查单模板")
    @Log(title = "应急TE单清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseEmerTeList baseEmerTeList)
    {
        baseEmerTeList.setUpdatedBy(getUserId().toString());
        baseEmerTeList.setUpdatedTime(new Date());
        return toAjax(baseEmerTeListService.updateBaseEmerTeList(baseEmerTeList));
    }

    /**
     * 删除应急TE单清单
     */
    @ApiOperation("删除检查单模板")
    @Log(title = "应急TE单清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(baseEmerTeListService.deleteBaseEmerTeListByIDs(IDs));
    }
}
